/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package MySqlAccess;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author tran tuan tai
 */
public class User
{
    public List<UserInfo> GetValidUser()
    {
        String sql = "SELECT * FROM WP_USERMETA WHERE META_KEY = \"wp_user_level\" AND (META_VALUE = 10 OR META_VALUE = 0)";
        return ExcuteQuery(sql);
    }

      public List<UserInfo> ExcuteQuery(String query)
     {
        List<UserInfo> result = new ArrayList<UserInfo>();

        try
        {
            DataAcessHelper da = DataAcessHelper.GetInstance();
            ResultSet rs =  da.ExcuteQuery(query);

            //int idxContent = rs.findColumn("post_content");
            int idxID = rs.findColumn("USER_ID");
            //int idxPosDate = rs.findColumn("POST_DATE");

            rs.beforeFirst();

            while(rs.next())
            {
                UserInfo info = new UserInfo();
                info.id = rs.getInt(idxID);
                result.add(info);
            }
            rs.close();
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }

        return result;
    }
}
